$(function () {
    findById();
});

/**
 * 根据id查询权限信息
 */

function findById() {
    let id = sessionStorage.getItem("userId");
    let result = myAjax("/api/rb/user/findById", {id: id}, "get");
    if (result != null) {
        setData(result.data);
    }
}

//赋值
function setData(data) {
    $("#username").val(data.username);
    $("#sex").val(data.sex);
    $("#age").val(data.age);
    $("#sno").val(data.sno);
    $("#className").val(data.className);
    $("#degree").val(data.degree);
    $("#admissionDate").val(data.admissionDate);
    $("#nickName").val(data.nickName);
    $("#phone").val(data.phone);
    $("#email").val(data.email);
    $("#address").val(data.address);
    $("#loginTime").val(data.loginTime);
    $("input[name='status'][value=" + data.status + "]").attr("checked", true);
}
function save() {
    let data = new FormData();
    data.append("id",sessionStorage.getItem("userId"));
    data.append("username", $("#username").val());
    data.append("file", $("#icon")[0].files[0]);
    data.append("sex", $("#sex").val());
    data.append("age", $("#age").val());
    data.append("sno", $("#sno").val());
    data.append("className", $("#className").val());
    data.append("degree", $("#degree").val());
    data.append("admissionDate", $("#admissionDate").val());
    data.append("nickName", $("#nickName").val());
    data.append("phone", $("#phone").val());
    data.append("email", $("#email").val());
    data.append("address", $("#address").val());
    data.append("loginTime", $("#loginTime").val());
    data.append("status", $("input:radio[name='status']:checked").val());
    let result = myImgAjax("/api/rb/user/update", data,"post");
    console.log(result);
    if(result.code === 200){
        alert("更新成功（== ^^ ==）！");
        x_admin_close();
        x_admin_father_reload();
        // }else if(result.result == "noLogin"){
        //     // window.open("/html/login.html","_self");
        //     x_admin_close();
        //     x_admin_father_reload();
    }else{
        alert("更新失败！");
    }
}